home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 19
/
Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso
/
Aminet
/
comm
/
net
/
ARemote1_00B.lha
/
ARemote
/
source
/
aremotedebug.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-27
|
7KB
|
196 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/AMarquee_protos.h>
#include <devices/inputevent.h>
#include <pragmas/AMarquee_pragmas.h>
struct Library * AMarqueeBase = NULL;
struct QSession * session = NULL;
FILE * fTest = NULL;
/* Takes user input until blank line is typed */
void ProcessDebugCommands(struct QSession * session)
{
while(1)
{
char debugline[500] = "\0\0\0\0\0\0\0\0";
char * keyword, * data;
ULONG dataLen = 0L;
LONG res;
printf("Enter your debug command now: "); fflush(stdout);
gets(debugline);
keyword = &debugline[2];
if (data = strchr(keyword,'='))
{
*data = '\0'; /* terminate the keyword */
data++;
dataLen = strlen(data)+1;
}
switch((int)(debugline[0]))
{
case '\0': res=QGo(session,0L); break;
case 'A': res=QSetMessageAccessOp(session, keyword, -1); break;
case 'm': res=QMessageOp(session, keyword, data, dataLen); break;
case 'a': res=QSetAccessOp(session, keyword); break;
case 's': res=QSetOp(session, keyword, data, dataLen); break;
case 'S': res=QStreamOp(session, keyword, data, dataLen); break;
case 'r': res=QRenameOp(session, keyword, data); break;
case 'D': res=QDebugOp(session, keyword); break;
case 'g': res=QGetOp(session, keyword, -1); break;
case 'd': res=QDeleteOp(session, keyword); break;
case 'i': res=QInfoOp(session); break;
case 'c': res=QSubscribeOp(session, keyword, -1); break;
case 'k': res=QClearSubscriptionsOp(session,atoi(keyword)); break;
case 'p': res=QPingOp(session); break;
default: printf("Command code %c was not recognized.\n",debugline[0]); break;
}
printf("(Op result was %i)\n",res);
if (debugline[0] == '\0') return;
}
}
void CleanExit(void)
{
printf("\nCleaning up...\n");
if (fTest) fclose(fTest);
if (session) QFreeSession(session); /* This MUST be done before we close the library! */
if (AMarqueeBase) CloseLibrary(AMarqueeBase);
printf("All done.\n");
}
/* Main program */
int main(int argc, char ** argv)
{
char * connectTo, * progName;
int port;
fTest = fopen("ie.bin","wb");
if (fTest == NULL)
{
printf("Couldn't open test file ie.bin\n");
exit(0);
}
printf("Usage Note: AMarqueeDebug [hostname=localhost] [myname=debug] [port=2957]\n");
atexit(CleanExit);
connectTo = (argc>1) ? argv[1] : "localhost";
progName = (argc>2) ? argv[2] : "ARemote";
port = (argc>3) ? atoi(argv[3]) : 20000;
if ((AMarqueeBase = OpenLibrary("amarquee.library",41L)) == NULL)
{
printf("Couldn't open amarquee.library v41!\n");
exit(RETURN_ERROR);
}
printf("Connecting to %s:%i\n",connectTo, port);
#ifdef ASYNC_CONNECT
if ((session = QNewSessionAsync(connectTo, port, progName)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
exit(RETURN_WARN);
}
#else
if ((session = QNewSession(connectTo, port, progName)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
exit(RETURN_WARN);
}
#endif
printf("Connected to server %s:%i\n",connectTo, port);
/* Setup some sample data */
/*
(void)QSetOp(session, "sampledata", "Kids", 5);
(void)QSetOp(session, "sampledata/Jeremy", "1", 2);
(void)QSetOp(session, "sampledata/Joanna", "2", 2);
(void)QSetOp(session, "sampledata/Joanna/nerd", "yep! :)", 8);
(void)QSetOp(session, "sampledata/Joellen", "3", 2);
(void)QSetOp(session, "sampledata/Charcoal", "Kitty!", 7);
(void)QGo(session, 0L);
*/
printf("Commands are:\n");
printf("\n");
printf("a wildhostpath Access control (default is /#?/#?)\n");
printf("A wildhostpath Access control for incoming messages (default in no access)\n");
printf("m hosts=data Send an active message to hosts\n");
printf("s path=data Set data node value\n");
printf("S path=data Stream data node value\n");
printf("r path=newlabel Rename data node\n");
printf("D debugstring Send debug string\n");
printf("g wildpath Get a node or nodes\n");
printf("c wildpath Subscribe to a node or nodes\n");
printf("k opID Klear subscriptions (by id or 0 for all)\n");
printf("d wildpath Delete a node or nodes\n");
printf("i Request info packet\n");
printf("p Request ping packet\n");
printf("<enter> Send accumulated transactions (GO!!)\n");
printf("\n");
printf("Press CTRL-F to enter commands, or CTRL-C to quit\n");
while(1)
{
struct QMessage * qMsg;
ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C) | (SIGBREAKF_CTRL_F);
/* Wait for next message from the server */
signals = Wait(signals);
if (signals & (1L << session->qMsgPort->mp_SigBit))
{
while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
{
struct InputEvent * ie = (struct InputEvent *) qMsg->qm_Data;
if ((ie)&&(qMsg->qm_DataLen == sizeof(struct InputEvent)))
{
#ifdef DEBUG_ME
printf("-----\n");
printf("ie_NextEvent = %p\n",ie->ie_NextEvent);
printf("class = %x, subClass = %x, code = %x(%c), qual = %x\n",
ie->ie_Class, ie->ie_SubClass, ie->ie_Code, ie->ie_Code, ie->ie_Qualifier);
switch(ie->ie_Class)
{
case IECLASS_RAWMOUSE: case IECLASS_POINTERPOS:
printf("ie_x = %i, ie_y = %i\n",ie->ie_position.ie_xy.ie_x, ie->ie_position.ie_xy.ie_y);
break;
case IECLASS_RAWKEY:
printf("ie_pdC1 = %i, ie_pdQ1 = %i, ie_pdC2 = %i, ie_pdQ2 = %i\n",
ie->ie_position.ie_dead.ie_prev1DownCode,
ie->ie_position.ie_dead.ie_prev1DownQual,
ie->ie_position.ie_dead.ie_prev2DownCode,
ie->ie_position.ie_dead.ie_prev2DownQual);
break;
}
printf("ie_addr = %p\n",ie->ie_position.ie_addr);
printf("ie_TimeStamp = %lu\n",ie->ie_TimeStamp);
#endif
printf("writing msg class %x subclass %x\n",ie->ie_Class, ie->ie_SubClass);
fwrite(ie, 1, sizeof(struct InputEvent), fTest);
}
else printf("Bad inputEvent %p %i\n",ie, qMsg->qm_DataLen);
FreeQMessage(session, qMsg);
}
}
if (signals & SIGBREAKF_CTRL_F) ProcessDebugCommands(session);
if (signals & SIGBREAKF_CTRL_C) break; /* Quit if CTRL-C pressed */
}
/* CleanExit() called here! */
}